﻿@model FieldControlViewModel
@{ 
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	string Percent = (Model.Settings[3].ToBoolean()) ? "%" : "";
	string minValue = (!string.IsNullOrEmpty(Model.Settings[0])) ? Model.Settings[0] : int.MinValue.ToString("F");
	string maxValue = (!string.IsNullOrEmpty(Model.Settings[1])) ? Model.Settings[1] : int.MaxValue.ToString("F");
	string pattern = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\"";
	}
	dataVal += " data-val-range=\"只能输入"+ minValue + "到"+ maxValue + "之间的数\"";
	dataVal += " data-val-range-min=\"" + minValue + "\"";
	dataVal += " data-val-range-max=\"" + maxValue + "\"";
	switch (Model.Settings[2])
	{
		case "0":
			pattern= "^[0-9]*$";
			dataVal += " data-val-regex=\"只能输入0-9的数字\"";
			break;
		case "1":
			pattern = @"^-?[0-9]+(\.?[0-9])?$";
			dataVal += " data-val-regex=\"只能保留1位小数\"";
			break;
		case "2":
			pattern = @"^-?[0-9]+(\.?[0-9]{1,2})?$";
			dataVal += " data-val-regex=\"只能保留2位小数\"";
			break;
		case "3":
			pattern = @"^-?[0-9]+(\.?[0-9]{1,3})?$";
			dataVal += " data-val-regex=\"只能保留3位小数\"";
			break;
		case "4":
			pattern = @"^-?[0-9]+(\.?[0-9]{1,4})?$";
			dataVal += " data-val-regex=\"只能保留4位小数\"";
			break;
		case "5":
			pattern = @"^-?[0-9]+(\.?[0-9]{1,5})?$";
			dataVal += " data-val-regex=\"只能保留5位小数\"";
			break;
		default:
			pattern = @"^-?[0-9]+(\.?[0-9]+)?$";
			dataVal += " data-val-regex=\"只能输入数字\"";
			break;
	}
	dataVal += " data-val-regex-pattern=\""+ pattern + "\"";
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\""+ Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
}
<div class="layui-input-inline">
	<input type="text" class="layui-input" name="@Model.Prefix@Model.FieldName" id="@Model.Prefix@Model.FieldName" value="@Model.FieldValue" @Html.Raw(dataVal) />
</div>
<div class="layui-input-inline layui-input-company">
	@Percent
	<span class="layui-bg-green">@Model.Description</span>
	<span style="color:red;" @Html.Raw(dataValMsg)></span>
</div>

